package cn.rkylin.oms.system.splitRule.handler;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.rkylin.apollo.common.util.HttpUtils;
import cn.rkylin.oms.common.event.EventHandler;
import cn.rkylin.oms.system.splitRule.event.OderReSplitEvent;

@Component
public class OderReSplitEventHandler extends EventHandler<OderReSplitEvent> {

	@Value("${executor.return.item.reSplit.url}")
	private String reSplitUrl;

	@Override
	public void onEvent(OderReSplitEvent event) throws Exception {
//		String url = "http://118.178.98.162:30003/orderManager/reSplitItem.action?shopid=" + event.getShopId(); 
		if (StringUtils.isBlank(reSplitUrl)){
			throw new Exception("店铺：" + event.getShopId() + "重新分单地址获得失败");
		}
		String url = reSplitUrl + "?shopid=" + event.getShopId();
		Map<String, String> postData = new HashMap<String,String>();
		List<String> repeatNames = new ArrayList<String>(); 
		List<String> repeatValues = new ArrayList<String>();
		//通过httpClient实现跨域调用的OMSJobExecutor重新分单的操作
		String result = HttpUtils.postMethod(url, postData, repeatNames, repeatValues);
		System.out.println(result);
		if (result.equals("error")) {
			throw new Exception("店铺：" + event.getShopId() + "重新分单失败");
		}
	}
}
